﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SimulacionRevision
{
    public partial class Form1 : Form
    {
    int a; 
    int c; 
    int m;
    int semilla;
    int semilla2;
    int semilla3;
    int semilla4;
    int vne;
    Double vpfg;
    int vtcfg;
    int vtcfl;
    int t;
    Double vtt;
    int sumas;

   
        public Form1()
        {
            InitializeComponent();
        }
  

        private void btValidar_Click(object sender, EventArgs e)
        {
        a =  Convert.ToInt32(tba.Text);
        c = Convert.ToInt32(tbc.Text);
        m = Convert.ToInt32(tbm.Text);
        semilla = Convert.ToInt32(tbsemilla.Text);
        //semilla = ((a * semilla) + c) % m;
        }

        private void btgenerar_Click(object sender, EventArgs e)
        {
            semilla = ((a * semilla) + c) % m;

            semilla2 = (((a+3) * (semilla+6)) + (c)) % 100;

            semilla3 = (((a + 6) * (semilla + 5)) + (c * 3)) % 8;

            semilla4 = (((a + 8) * (semilla + 2)) + (c )) % 8;
            semilla3 = ((a * semilla3) + c) % 8;

            vne = ((a * semilla) + c) % 20;
            ne.Text = Convert.ToString(vne);
            ne2.Text = Convert.ToString(vne);

            vpfg = (((a + 3) * (semilla2 + 6)) + (c)) % 100;
            vpfg = vpfg / 100;
            pfg.Text = Convert.ToString(vpfg);
            pfg2.Text = Convert.ToString(vpfg);


            vtcfg = (((a + 6) * (semilla3 + 5)) + (c * 3)) % 8;
            tcfg.Text = Convert.ToString(vtcfg);

            vtcfl = (((a + 8) * (semilla4 + 2)) + (c)) % 8;
            tcfl.Text = Convert.ToString(vtcfl);
        }

        public void btcalcular_Click(object sender, EventArgs e)
        {
            vne = Convert.ToInt32(ne.Text);
            vpfg = Convert.ToDouble(pfg.Text)/100;
            vtcfg = Convert.ToInt32(tcfg.Text);
            vtcfl = Convert.ToInt32(tcfl.Text);
            t = Convert.ToInt32(tb.Text);

            for (int i = 1; i < vne+1; i++)
            {
                sumas = sumas + t/i;
            }
            vtt = ((vne * vpfg * vtcfg) + (vne * (1 - vpfg) * vtcfl)) + sumas;
            tbtt.Text = Convert.ToString(vtt);

        }


       
                        private void ne_TextChanged(object sender, EventArgs e)
                        {
                            ne2.Text = ne.Text;
                        }

                        private void pfg_TextChanged(object sender, EventArgs e)
                        {
                            pfg2.Text = pfg.Text;
                        }

                        private void tba_KeyPress(object sender, KeyPressEventArgs e)
                        {
                            if (!(char.IsNumber(e.KeyChar)) && (e.KeyChar != (char)Keys.Back))
                            {
                                MessageBox.Show("Solo se permiten numeros", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                e.Handled = true;
                                return;
                            }
                        }

                        private void tbsemilla_KeyPress(object sender, KeyPressEventArgs e)
                        {
                            if (!(char.IsNumber(e.KeyChar)) && (e.KeyChar != (char)Keys.Back))
                            {
                                MessageBox.Show("Solo se permiten numeros", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                e.Handled = true;
                                return;
                            }
                        }

                        private void tbc_KeyPress(object sender, KeyPressEventArgs e)
                        {
                            if (!(char.IsNumber(e.KeyChar)) && (e.KeyChar != (char)Keys.Back))
                            {
                                MessageBox.Show("Solo se permiten numeros", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                e.Handled = true;
                                return;
                            }
                        }

                        private void tbm_KeyPress(object sender, KeyPressEventArgs e)
                        {
                            if (!(char.IsNumber(e.KeyChar)) && (e.KeyChar != (char)Keys.Back))
                            {
                                MessageBox.Show("Solo se permiten numeros", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                e.Handled = true;
                                return;
                            }
                        }

                        private void ne_KeyPress(object sender, KeyPressEventArgs e)
                        {
                            if (!(char.IsNumber(e.KeyChar)) && (e.KeyChar != (char)Keys.Back))
                            {
                                MessageBox.Show("Solo se permiten numeros", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                e.Handled = true;
                                return;
                            }
                        }

                        private void pfg_KeyPress(object sender, KeyPressEventArgs e)
                        {
                            if (!(char.IsNumber(e.KeyChar)) && (e.KeyChar != (char)Keys.Back))
                            {
                                MessageBox.Show("Solo se permiten numeros", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                e.Handled = true;
                                return;
                            }
                        }

                        private void tcfg_KeyPress(object sender, KeyPressEventArgs e)
                        {
                            if (!(char.IsNumber(e.KeyChar)) && (e.KeyChar != (char)Keys.Back))
                            {
                                MessageBox.Show("Solo se permiten numeros", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                e.Handled = true;
                                return;
                            }
                        }

                        private void tcfl_KeyPress(object sender, KeyPressEventArgs e)
                        {
                            if (!(char.IsNumber(e.KeyChar)) && (e.KeyChar != (char)Keys.Back))
                            {
                                MessageBox.Show("Solo se permiten numeros", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                e.Handled = true;
                                return;
                            }
                        }

                        private void tb_KeyPress(object sender, KeyPressEventArgs e)
                        {
                            if (!(char.IsNumber(e.KeyChar)) && (e.KeyChar != (char)Keys.Back))
                            {
                                MessageBox.Show("Solo se permiten numeros", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                e.Handled = true;
                                return;
                            }
                        }



      
    }
}



